package com.quanyan.club.web;

import com.alibaba.fastjson.JSON;
import com.quanyan.api.APIResponse;
import com.quanyan.api.enums.ApiResponseEnum;
import com.quanyan.club.entity.vo.req.movement.ReqClubListInfo;
import com.quanyan.club.entity.vo.req.movement.ReqPointPrise;
import com.quanyan.club.entity.vo.req.movement.ReqSendCommentMovement;
import com.quanyan.club.entity.vo.req.movement.ReqSubmitMovement;
import com.quanyan.club.entity.vo.resp.movement.*;
import com.quanyan.club.service.ClubIntegralService;
import com.quanyan.club.service.ClubMovementService;
import com.quanyan.common.Plugin.PageObj;
import com.quanyan.common.exception.BizException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author xian-guo
 * @email 498152332@qq.com
 * @date 2016/12/1.
 */
@RestController
@RequestMapping(value = "/api/club/integral/")
public class ClubIntegralController {
    private static Logger logger = Logger.getLogger(ClubIntegralController.class);
    @Autowired
    private ClubIntegralService clubIntegralService;

    /**
     * 俱乐部积分排名
     * @param reqClubListInfo
     * @return
     */
    @RequestMapping(value = "getClubIntegralRank", method = RequestMethod.POST)
    public APIResponse<Map<String,Object>> getClubIntegralRank(@RequestBody ReqClubListInfo reqClubListInfo){
        logger.warn("getClubIntegralRank--------------->"+JSON.toJSONString(reqClubListInfo));
        //getUid(request,true);
        return clubIntegralService.getClubIntegralRank(reqClubListInfo);
    }




    public int getUid(HttpServletRequest request,boolean isNeedLogin){
        Object uidObj = request.getAttribute("uid");
        int uid = -1;
        if (uidObj != null){
            uid = Integer.valueOf(String.valueOf(uidObj));
        }
        if (uid == -1 && isNeedLogin){
            throw new BizException(ApiResponseEnum.NEED_USER_LOGIN);
        }
        return uid;
    }
}
